Home:ALL Converter>android supporting different resolution with layout folder

android supporting different resolution with layout folder

Ask Time:2018-11-14T18:53:44         Author:mishti

Json Formatter

I am creating layouts for an app but the problem is layout is perfect on all large devices but not suits on hdpi. So I think to create hdpi folder separate for layouts. I choose android resource directory and choose density as hdpi but not working for only hdpi devices. I tried dimensions and screen width also but not working. Can you please help me how can I improve it.

Layout Code

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorPrimary">


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/combine_bg"
        android:layout_marginTop="@dimen/dp20"
        android:layout_marginBottom="@dimen/dp20"
        android:layout_marginRight="@dimen/dp20">


        <TextView
            android:id="@+id/txtWelcomeTo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/welcome_to"
            android:layout_marginTop="@dimen/dp170"
            android:layout_marginLeft="@dimen/dp10"
            android:textSize="@dimen/dp15"
            android:textColor="@android:color/black" />


        <TextView
            android:id="@+id/txtPrivateCare"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/the_private_care_masters"
            android:layout_marginLeft="@dimen/dp10"
            android:textStyle="bold"
            android:textColor="@android:color/black"
            android:layout_below="@id/txtWelcomeTo" />


        <EditText
            android:id="@+id/etemail"
            android:layout_width="@dimen/dp190"
            android:layout_height="wrap_content"
            android:layout_below="@id/txtPrivateCare"
            android:layout_marginLeft="@dimen/dp10"
            android:hint="@string/email_phone"
            android:layout_marginTop="@dimen/dp20" />


        <EditText
            android:id="@+id/etPassword"
            android:layout_width="@dimen/dp190"
            android:layout_height="wrap_content"
            android:layout_below="@id/etemail"
            android:layout_marginLeft="@dimen/dp10"
            android:layout_marginTop="@dimen/dp10"
            android:hint="@string/password"

            />


        <ImageButton
            android:id="@+id/loginButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/login_btn"
            android:background="@android:color/transparent"
            android:layout_below="@id/etemail"
            android:layout_marginLeft="@dimen/dp25"
            android:layout_toRightOf="@id/etemail" />


        <CheckBox
            android:id="@+id/chkRememberMe"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/etPassword"
            android:layout_marginLeft="@dimen/dp10"
            android:layout_marginTop="@dimen/dp10"
            android:text="@string/remember_me"
            android:textSize="@dimen/dp12"

            />


        <TextView
            android:id="@+id/txtForgotPwd"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/chkRememberMe"
            android:text="@string/forgot_pwd"
            android:layout_below="@id/etPassword"
            android:layout_marginTop="@dimen/dp17"
            android:textSize="@dimen/dp12"
            android:layout_marginLeft="@dimen/dp15"

            />


        <TextView
            android:id="@+id/txtSignUp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/not_have_account"
            android:layout_below="@id/txtForgotPwd"
            android:layout_marginTop="@dimen/dp30"
            android:textSize="@dimen/dp12"
            android:layout_marginLeft="@dimen/dp15"

            />


    </RelativeLayout>
</RelativeLayout>

And screenhsot of .psd which I want to create

screenhsot of .psd which I want to create

And mine layout on hdpi device:

enter image description here

How can I resolve the problem please help

dimens.xml

<dimen name="dp1">1dp</dimen>
    <dimen name="dp2">2dp</dimen>
    <dimen name="dp3">3dp</dimen>
    <dimen name="dp4">4dp</dimen>

dimens.xml-large

<dimen name="dp1">1.5dp</dimen>
<dimen name="dp2">3.0dp</dimen>
<dimen name="dp3">4.5dp</dimen>
<dimen name="dp4">6.0dp</dimen>

dimes.xml - xlarge

 <dimen name="dp1">2.0dp</dimen>
    <dimen name="dp2">4.0dp</dimen>
    <dimen name="dp3">6.0dp</dimen>

Author:mishti,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/53298507/android-supporting-different-resolution-with-layout-folder
André Sousa :

You should be using sp instead of dp for your text sizes.\nFrom the documentation:\n\nsp\nScale-independent Pixels - this is like the dp unit, but it is also scaled by the user's font size preference. It is recommended you use this unit when specifying font sizes, so they will be adjusted for both the screen density and user's preference.\n",
2018-11-14T11:42:10
yy